# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=dtc
pkgver=1.7.0
pkgrel=2
pkgdesc="Device Tree Compiler"
url="https://git.kernel.org/pub/scm/utils/dtc/dtc.git/"
arch="all"
license="GPL-2.0-or-later"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	bison
	flex
	py3-setuptools
	python3-dev
	swig
	"
checkdepends="coreutils"
subpackages="$pkgname-dev libfdt py3-libfdt-pyc py3-libfdt:py3_libfdt"
source="https://kernel.org/pub/software/utils/dtc/dtc-$pkgver.tar.xz
	install-pylibfdt-to-destdir.patch
	pyscm.patch
	fix-tests-for-Python3.12.patch
	"

prepare() {
	default_prepare
	sed -i s:-Werror::g "$builddir"/Makefile
	sed -i "s|@VERSION@|$pkgver|" setup.py
}

build() {
	make -j1
}

check() {
	make check
}

package() {
	make -j1 DESTDIR="$pkgdir" PREFIX=/usr install
	rm -f "$pkgdir"/usr/lib/*.a
}

libfdt() {
	pkgdesc="Device tree library"
	license="GPL-2.0-or-later OR BSD-2-Clause"
	amove usr/lib/libfdt*
}

py3_libfdt() {
	pkgdesc="Device tree library for Python 3"
	depends="python3"
	amove usr/lib/python3*
}

sha512sums="
d3ba6902a9a2f2cdbaff55f12fca3cfe4a1ec5779074a38e3d8b88097c7abc981835957e8ce72971e10c131e05fde0b1b961768e888ff96d89e42c75edb53afb  dtc-1.7.0.tar.xz
1c43dfae8d15861c4f0170f0df9ba63d197ab3be50e39fe5748e547074c52dc7b042ca5e9c64d3d4bb0a8e8cde8df7e71660cde93e9512923405c38debcaa01c  install-pylibfdt-to-destdir.patch
e74768f6bcbe0ba8060c7b0b449e533b2fbbf3ddc1c869b98cf3f78a858c63ba1d7d57b5163eb5be048c6f0be023360f709d621e2f88d4332a7ef8e8d125cc09  pyscm.patch
2fc10469b4c1f5016cdccd1a1e24d1f0984267c88efe88d268d52d9a49c441d832f53bf004a5223810c82e0f10cf5b515d6a6ddb56e49ca5bb86b55724634f0b  fix-tests-for-Python3.12.patch
"
